﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using PMP.Data;
using PMP.Models;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace PMP.Controllers
{
    public class QuestionController : Controller
    {
        private readonly PMPContext _context;

        public QuestionController(PMPContext context)
        {
            _context = context;
        }

        public async Task<IActionResult> DateList()
        {
            var list = await _context.Daily.ToListAsync();
            ViewBag.list = list;
            return View();
        }
        public async Task<IActionResult> Date(Daily daily)
        {
            List<Question> list = await _context.Question.Where(x => x.DID == daily.ID).ToListAsync();
            foreach (var question in list)
            {
                question.Options = await _context.Option.Where(x => x.QID == question.ID).ToListAsync();
            }
            ViewBag.list = list;
            ViewBag.daily = daily;

            return View();
        }

    }
}
